package xdu.lz.stage3_classloader.chapter2_classloader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MyClassLoaderTest {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {


        MyClassLoader classLoader = new MyClassLoader("myclassLoader");

        /**
         * 注意：被类加载器加载的时候不会初始化【在连接阶段才初始化】，所以不执行静态代码块的代码
         */
        Class<?> clazz = classLoader.
                loadClass("xdu.lz.stage3_classloader.chapter2_classloader.SimpleObj");

        System.out.println(clazz);
        System.out.println(clazz.getClassLoader());


        System.out.println("=================");
        Object instance = clazz.newInstance();
        Method method = clazz.getMethod("say", new Class<?>[]{});
        Object res = method.invoke(instance, new Object[]{});
        System.out.println(res);
    }
}
